#include <iostream>
using namespace std;
//内存释放分配在堆上, 释放会自动销毁, 是否由调用者销毁
template<typename T>
class smart_pointer
{
private:
    T* myrawpointer;
public:
    smart_pointer(T* pData):myrawpointer(pData){};
    ~smart_pointer(){delete myrawpointer;};
    //复制构造函数
    smart_pointer(const smart_pointer& anotherSP);
    smart_pointer& operator=(const smart_pointer& anotherSP) const;
    T& operator *() const
    {
        return *(myrawpointer); //值引用传递
    }

    T* operator ->()
    {
        return myrawpointer;
    }
};

class Test
{
public:
    void DisplayName(void)
    {
        cout << "Myname is shang" << endl;
    }
};

int main(int argc, char const *argv[])
{
    smart_pointer<Test>ptr(new Test);
    ptr->DisplayName();
    return 0;
}
